package printnum;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.generated.StormTopology;
import org.apache.storm.topology.TopologyBuilder;

public class NumberTopology {
    public static void main(String[] args) throws Exception {
        NumberSpout numberSpout = new NumberSpout();
        PrintBolt printBolt = new PrintBolt();

        // 创建一个拓扑构建者对象，通过这个对象绑定组件之间的关系
        TopologyBuilder builder = new TopologyBuilder();

        // 绑定数据源组件
        // 参数1：组件id，要求唯一性
        // 参数2：组件的实例对象
        builder.setSpout("numberSpout", numberSpout);

        // 绑定Bolt组件，传入组件id(必须要唯一)，产生关系
        builder.setBolt("printBolt", printBolt)
                .globalGrouping("numberSpout");

        // 创建拓扑对象
        StormTopology topology = builder.createTopology();

        // 创建配置对象
        Config config = new Config();
        // 获取Storm的本地运行对象
        LocalCluster localCluster = new LocalCluster();

        // 提交拓扑
        localCluster.submitTopology("numberTopology", config, topology);
    }
}
